import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

class MyAvatarWidget extends StatelessWidget {
  final String image;
  final double borderRadius;
  final double imageWidth;

  const MyAvatarWidget({
    super.key,
    required this.image,
    this.imageWidth = 50.0,
    this.borderRadius = 8.0,  // 默认圆角半径
  });

  @override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
      imageUrl: image,
      width: imageWidth,
      height: imageWidth,
      placeholder: (context, url) => const Center(
        child: SizedBox(
          width: 20.0,
          height: 20.0,
          child: CircularProgressIndicator(strokeWidth: 2.0),
        ),
      ),
      errorWidget: (context, url, error) => const Icon(Icons.error),
      imageBuilder: (context, imageProvider) => CircleAvatar(
        backgroundImage: imageProvider,
        radius: 20,
      ),
    );
  }
}
